var express = require('express');
var todoApi = require('./routes/todo-api')
var hentaiApi = require('./routes/hentai-api')
var testApi = require('./routes/test-api')
var router = express.Router();
router.use('/todos', todoApi)
router.use('/hentai', hentaiApi)
router.use('/test', testApi)

router.use(function(req, res, next) {
  var err = Error('Not Found');
  err.status = 404;
  next(err);
});

router.use(function(data, req, res, next) {
    if (data instanceof Error){
        var codeStatus = data.status || 601
        var message = data.message
    }else{
        var codeStatus = data.status || 200
        var message = data.message || ''
        var value = data.value || data
    }
    res.status(200)
    res.json({
        message: message,
        data: value || {},
        code: codeStatus
    });
});

module.exports = router
